package org.example.admin.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.entity.User;

import javax.servlet.http.HttpServletRequest;

public class ConditionWithQuery {

    private String name;
    private String gender;
    private String email;
    private Integer status;
    private String begin;
    private String end;

    public QueryWrapper<User> withQuery (HttpServletRequest req){

        name = req.getParameter("name");
        gender = req.getParameter("gender");
        email = req.getParameter("email");
        if (req.getParameter("status")!=null){
            status = Integer.valueOf(req.getParameter("status"));
        }
        begin = req.getParameter("begin");
        end = req.getParameter("end");

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();

        if (name!=""&&name!=null){
            queryWrapper.like("u_name",name);
        }
        if (!"-1".equals(gender)&&gender!=null){
            queryWrapper.like("u_sex",gender);
        }
        if (email!=""&&email!=null){
            queryWrapper.like("u_email",email);
        }
        if (status!=-1){
            queryWrapper.eq("u_status",status);
        }
        if (begin!=""&&begin!=null){
            queryWrapper.ge("u_register_date",begin);
        }
        if (end!=""&&end!=null){
            queryWrapper.le("u_register_date",end);
        }

        return queryWrapper;
    }
}
